#!/usr/bin/env python
# -*- encoding: utf-8 -*-

from socket import *
import select

PORT = 9999

serv_sock = socket(AF_INET, SOCK_DGRAM)
serv_sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
serv_sock.bind(('', PORT))

args = [serv_sock], [], []
print "select started..."

while 1:
	print "== before select() =="
	reti, retw, rete = select.select(*args)
	print "== after select() =="
	for sock in reti:
		print "메시지 수신 대기..."
		msg, addr = sock.recvfrom(1024)
		print "메시지 수신 완료"
		print msg, addr
		print "메시지 송신중..."
		sock.sendto(msg, addr)
		print "메시지 송신 완료"
